document.getElementById("search").onclick=function(){
	search();
}
document.getElementById("key").onkeyup=function(){
	if(event.keyCode===13){
		search();
	}
}
function search(){
	var key=document.getElementById("key").value;
	if(/^ *$/.test(key)){
		showErrorInfo("请输入搜索关键字，如实验的学段、科目、书本、实验名等")
		return false;
	}
	jQuery.ajax({
		"url":"/search_exp/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"data":{"key":key},
		"success":function(data){
			if(!data.status){
				showError(data.content);
				return false;
			}
			else{
				$("tbody>tr").remove()
				var data=data.content;
				var tab=document.getElementById("tab");
				for(var i=0;i<data.length;i++){
					var tr=document.createElement("tr")
					tr.style.cursor="pointer";
	
					var td=document.createElement("td")
					td.textContent=data[i].content;	
					tr.setAttribute("data",JSON.stringify(data[i]))

					tr.appendChild(td)
					tr.onclick=function(){
						var data=this.getAttribute("data")
						data=JSON.parse(data)
						var p=window.opener.document.getElementById("test")
						console.log(p)
						p.value=data.content;
						p.setAttribute("sid",data.id);
						p.setAttribute("name",data.name);
						window.close()
					}
					
					tab.appendChild(tr)
					
				}
			}
		}
	})
}
